<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户管理</title>
    <script type="text/javascript" src="static/common/js/common.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="UserCtrl">
    <div class="row">
        <ui-container url="system/user/list" key="user-list-00">
            <ui-search-form>
                <search-input class="col-md-2" name="realName" placeholder="请输入用户姓名"></search-input>
                <search-input class="col-md-2" name="workNo" placeholder="请输入工号"></search-input>
                <search-input class="col-md-2" name="mobile" placeholder="请输入手机号"></search-input>
            </ui-search-form>
            <ui-table-tool>
                <a class="btn btn-sm btn-primary" href="javascript:void(0);" ng-click="addOpen('system/user/add')" >新增</a>
                <a class="btn btn-sm btn-primary" href="javascript:void(0);" onclick="reSet()">重置</a>
            </ui-table-tool>
            <ui-table>

            </ui-table>
            <table-page/>
        </ui-container>
    </div>
    <%--<div class="row">--%>
        <%--<a class="btn btn-sm btn-primary" href="javascript:void(0);" ng-click="exportTemplate()" target="_blank" >导出模板</a>--%>
        <%--<a class="btn btn-sm btn-primary" href="javascript:void(0);" ng-click="exportDatas()" target="_blank" >导出用户</a>--%>
        <%--<a class="btn btn-sm btn-success" href="./html/userhelper.html" target="_blank" >导出帮助</a><br/>--%>
        <%--<label>用户导入</label>--%>
        <%--<ui-upload url="system/user/import" success="uploadSuccess"></ui-upload>--%>
    <%--</div>--%>
</div>
<%--<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">--%>
    <%--<div class="modal-dialog">--%>
        <%--<div class="modal-content">--%>
            <%--<div class="modal-header">--%>
                <%--<button type="button" class="close" data-dismiss="modal"--%>
                        <%--aria-hidden="true">×--%>
                <%--</button>--%>
                <%--<h4 class="modal-title" id="myModalLabel">--%>
                    <%--是否确认删除？--%>
                <%--</h4>--%>
            <%--</div>--%>
            <%--<div class="modal-body">--%>
                <%--按下 ESC 按钮退出。--%>
            <%--</div>--%>
            <%--<div class="modal-footer">--%>
                <%--<button type="button" class="btn btn-default"--%>
                        <%--data-dismiss="modal">关闭--%>
                <%--</button>--%>
                <%--<button id="confirm" type="button" class="btn btn-primary">--%>
                    <%--确认--%>
                <%--</button>--%>
            <%--</div>--%>
        <%--</div>--%>
    <%--</div>--%>
<%--</div>--%>

<script>
    angular.module('myApp',['ui.table']);
    angular.module('myApp').controller('UserCtrl', function($scope){
        function doBatchDel(selectedItems) {
            const uiContainerCtrl=$scope['user-list-00'];
            if(!selectedItems||selectedItems.length<=0){
                toastr.error("没有选中删除对象")
                return;
            }
            const ids = selectedItems.map(m => m.id);
            $.ajax({
                url:'system/user/batchdel',
                data:{ids:ids.join(",")}
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.msg);
                    uiContainerCtrl._queryData({});
                }else{
                    toastr.error(result.msg);
                }

            }).fail(function (r) {
                toastr.error("服务器异常"+r);

            });

        }
        function doDel(id) {
            const uiContainerCtrl=$scope['user-list-00'];
            $.ajax({
                url:'system/user/delete',
                data:{id:id}
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.msg);
                    uiContainerCtrl._queryData({});
                }else{
                    toastr.error(result.msg);
                }

            }).fail(function (r) {
                toastr.error("服务器异常"+r);

            });

        }
        $scope.addOpen = function (url) {
            window.reloadTable=$scope['user-list-00']._queryData;
            window.location.href=url;
        }
        $scope.uploadSuccess = function (returndata) {
            $("#userImport").find(".upload-result").remove();
            if(returndata.data){
                $("#userImport").append('<a class="btn btn-sm btn-success upload-result" href="system/user/down?fileKey='+returndata.data["fileKey"]+'" target="_blank" >下载导入失败的记录</a>');
            }
            toastr.success("总共"+returndata.data["totalNums"]+"条,成功"+returndata.data["successNums"]+"条");
        }
        $scope.exportDatas = function(){
            var params = {
                url: 'system/user/export',
                type: "POST"
            };
            var exportForm = $("<form>");
            $(exportForm).css("display", "none");
            $(exportForm).attr('target', 'targetFrame');
            $(exportForm).attr('method', params.type);
            $(exportForm).attr('action', params.url);
            exportForm = exportForm.appendTo($("body"));
            exportForm.submit();
            exportForm.remove();
        }
        $scope.exportTemplate = function(){
            var params = {
                url: 'system/user/exporttemplate',
                type: "POST"
            };
            var exportForm = $("<form>");
            $(exportForm).css("display", "none");
            $(exportForm).attr('target', 'targetFrame');
            $(exportForm).attr('method', params.type);
            $(exportForm).attr('action', params.url);
            exportForm = exportForm.appendTo($("body"));
            exportForm.submit();
            exportForm.remove();
        }

        $scope.addUser = function (items) {
            console.info(items)
        }
        //每一列的操作按钮
        $scope._operateColumns = [{text:'编辑',click:function (data) {
            $scope.addOpen("system/user/update.htm?id="+data.id);
        }},{text:'删除',click:function (data) {
            doDel(data.id)
        }}]
        $scope._columns=[{name:'code',head:'工号'},{name:'realName',head:'用户姓名'},
            {name:'idCard',head:'身份证号'},{name:'mobile',head:'手机号'},
            {name:'hireDate',head:'入职时间',render(data,value){
                return value == null ? '': new Date(value).format("yyyy-MM-dd hh:mm:ss");
            }},
            {name:'leaveDate',head:'离职时间',render(data,value){
                return value == null ? '': new Date(value).format("yyyy-MM-dd hh:mm:ss");
            }},
            {name:'onJob',head:'在职状态',render(value,data){return value=='0'?'离职':'在职'}},
            {name:'organizationName',head:'所在机构'},
            {name:'settlementType',head:'结算类型',render(data,value){
                switch (value+""){
                    case "0":
                        return "投递员价";
                    case "1":
                        return "合作站点价";
                    case "2":
                        return "合作商价";
                    case "":
                        return "直接定价";
                    default:return "";

                }
            }}];

        $scope._btns=[{text:'批量删除',click:doBatchDel}];
    });
</script>
</body>
</html>